//
//  CollectionViewController.m
//  AudioBook_A
//
//  Created by 蒙奇-D-小路 on 15/4/17.
//  Copyright (c) 2015年 Sansan. All rights reserved.
//

#import "CollectionViewController.h"

@interface CollectionViewController ()

@end

@implementation CollectionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.collectTableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStylePlain];
    self.collectTableView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.collectTableView];
    
    self.collectTableView.delegate = self;
    self.collectTableView.dataSource = self;
    
    // 创建导航栏编辑按钮
    self.navigationItem.rightBarButtonItem = self.editButtonItem;
    
    
    
    // Do any additional setup after loading the view.
}

// 2. 重写系统编辑按钮
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];
    
    // 执行tabelview 的编辑方法
    [self.collectTableView setEditing:editing];
    
}

// 3.询问哪些行需要编辑
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

// 4. 设置编辑类型
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    // 删除
    return UITableViewCellEditingStyleDelete;
    
    
}


// 5. 开始编辑
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
        // 删除对应的cell
        // 参数2, 需要填一个数组类型, 数组中的元素是当前cell的下标
        [self.collectTableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationLeft];
    
}


// 设置删除按钮标题
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return @"删除";
}




// 两个必须实现的方法之一
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 20;
}

// 两个必须实现的方法之一
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIndentiller = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentiller];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIndentiller];
    }
    
    
    
    
    // cell 点击后没有阴影效果
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    
    return cell;
}







- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
